﻿using System.Linq;
using TyNetCoreBlog.Helpers;
using TyNetCoreBlog.Models.Data;
using TyNetCoreBlog.Repository.RepositoryBase;
using TyNetCoreBlog.Models.Entities;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace TyNetCoreBlog.Repository
{
    public class UserRepository : RepositoryBase<User, int>, IUserRepository
    {
        public UserRepository(AppDbContext dbContext): base(dbContext)
        {
        }


        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<User> GetUserInfoAsync(int userId)
        {
            var us = await DbContext.Set<User>().FindAsync(userId);
            return us;
        }


        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public User Login(string username, string password)
        {
            string pwd = Md5Encrypt.GetMd5Str(password);
            var usr = DbContext.Set<User>().SingleOrDefault(u => u.UserName == username && u.Password == pwd);
            return usr;
        }

    }
}
